package test.adddata;

import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;
import utils.SmallTool;

import java.util.List;
import java.util.Set;

/**
 * @Author: gcr
 * @Date: 2022-5-25 16:09
 */
public class 排查256G服务器pm主表pmid是不是重复 {
    @SneakyThrows
    public static void main(String[] args) {

        String dbNameMy = "pubmed_vip_extend_0328_33771437";

        Set<Integer> allPmid = new ConcurrentHashSet<>();
        Set<Integer> allSamePmidIds = new ConcurrentHashSet<>();

        int breakSize = 100000;

        SmallTool.printMemory();
//        Db use3307 = Db.use(DSFactory.get("taiyi"));
        Db use3307 = Db.use();
        String allDate = "select max(id) as ids  from " + dbNameMy;
        Entity query = use3307.query(allDate).get(0);
        SmallTool.printMess("最大的id 是" + query.getStr("ids"));
        Integer count = query.getInt("ids");
        int pageSize = count / breakSize + 1;
        SmallTool.printMess("全部页码+++++++++" + pageSize);
        SmallTool.printMess("任务开始+++++++++++++++++++++++++++++++++++++++++++++++++++++");
        for (int i = 1; i <= pageSize; i++) {
            int start = breakSize * (i - 1) + 1;
            int end = i * breakSize;
            SmallTool.printMess("开始页码++" + i + "++id++" + start + "结束id++++" + end);
            String meSql = "select id,pmid from " + dbNameMy + " where id between " + start + " and " + end;
            List<Entity> queryMe = use3307.query(meSql);
            queryMe.parallelStream().forEach(pmDeatil -> {
                Integer id = pmDeatil.getInt("id");
                Integer pmid = pmDeatil.getInt("pmid");
                if (allPmid.contains(pmid)) {
                    allSamePmidIds.add(id);
                } else {
                    allPmid.add(pmid);
                }
            });
        }
        FileUtil.writeString(JSON.toJSONString(allSamePmidIds), "/usr/local/gcr/256Gpm主表重复pmid的id集合", "UTF-8");

    }
}
